<template>
	<view class="beforeOrder">
		<view class="add dFlex jStart_aStart" @tap='selAdd' v-if="!source">	
			<view class="addIcon imgPublic">
				<image src="https://zl-tuangou.oss-cn-qingdao.aliyuncs.com/cMini/addIcon.png" mode="widthFix"></image>
			</view>
			<view class="unselAdd dFlex jBetween_aCenter" v-if='!addInfo.id'>
				<view class="toast">选择提货人</view>
				<view class="rightIcon imgPublic">
					<image src="https://zl-tuangou.oss-cn-qingdao.aliyuncs.com/cMini/rightIcon.png" mode="widthFix"></image>
				</view>
			</view>
			<view class="selAdd" v-if="addInfo.id">
				<view class="userInfo">
					<text class="username">{{addInfo.receiver}}</text>
					<text class="tel">{{addInfo.phone}}</text>
				</view>
				<view class="showAdd">{{addInfo.address+addInfo.address_detail}}</view>
			</view>
		</view>
		<view class="teamInfo" @click='selZiti'>
			<view class="userInfo dFlex jBetween_aCenter" v-if='leaderInfo.address_id'>
				<view class="tuanzhang dFlex jStart_aCenter">
					<view class="userTx imgPublic">
						<image v-if="leaderInfo.store_imgs" :src="leaderInfo.store_imgs"></image>
						<image v-else src="https://zl-tuangou.oss-cn-qingdao.aliyuncs.com/assets/img/store.jpg"></image>
					</view>
					<text style="display: inline-block;width: 230px;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;">{{leaderInfo.store_name?leaderInfo.store_name:leaderInfo.receiver}}</text>
					<view class="tag">提货点</view>
				</view>
			</view>
			<view class="base dFlex jBetween_aCenter">
				<view class="baseLeft dFlex jStart_aStart">
					<view class="titles dFlex jStart_aStart">
						<view class="addIcon imgPublic">
							<image src="https://zl-tuangou.oss-cn-qingdao.aliyuncs.com/cMini/add1.png" mode="widthFix"></image>
						</view>
						<text>提货地址:</text>
					</view>
					<view class="info_content" v-if='leaderInfo.address_id'>{{leaderInfo.address_detail?leaderInfo.address_detail:leaderInfo.address}}</view>
					<view class='info_content' v-else>请选择提货地址</view>
				</view>
			</view>
		</view>
		<view class="shopMsg">
			<view class="shopList">
				<view class="shopInfo dFlex jStart_aStart" v-for="(item,index) in shopInfo" :key='index'>
					<view class="shopImg imgPublic">
						<image :src="item.main_img" mode="widthFix"></image>
					</view>
					<view class="other">
						<view class="dFlex jBetween_aStart">
							<view class="shopName">{{item.title}}</view>
							<view class="price">¥{{item.showPrice?item.showPrice:'0.00'}}</view>
						</view>
						<view class="selSpec dFlex jBetween_aCenter">
							<view class="spec">{{item.specName}}</view>
							<view class="count">x{{item.count}}</view>
						</view>
					</view>
				</view>
			</view>
			<view class="orderLine dFlex jBetween_aCenter">
				<view class="lineTit">商品金额</view>
				<view class="lineVal">¥{{shopPrice.toFixed(2)}}</view>
			</view>

			
			<view class="orderLine dFlex jBetween_aCenter" >
				<view class="lineTit">平台优惠</view>
				<view class="lineVal dFlex jEnd_aCenter">
					<view class="condition" v-if="coupon.length" @tap='couponFlag = true'>{{cpCount}}元</view>
					<text class="toast" v-else>暂无可用优惠</text>
					<view class="rightIcon imgPublic">
						<image src="https://zl-tuangou.oss-cn-qingdao.aliyuncs.com/cMini/rightIcon.png" mode="widthFix"></image>
					</view>
				</view>
			</view>
		</view>
		<!-- <view class="shopMsg">
			<view class="orderLine dFlex jBetween_aCenter" @tap='changePay("wxpay")'>
				<view class="lineTit dFlex jStart_aCenter">
					<view class="titIcon imgPublic">
						<image src="https://zl-tuangou.oss-cn-qingdao.aliyuncs.com/cMini/wxIcon2.png" mode="widthFix"></image>
					</view>
					<text>微信支付</text>
				</view>
				<view class="lineVal dFlex jEnd_aCenter">
					<view class="statusIcon imgPublic">
						<image v-if="paytype != 'wxpay'" src="https://zl-tuangou.oss-cn-qingdao.aliyuncs.com/cMini/unsel.png" mode="widthFix"></image>
						<image v-if="paytype == 'wxpay'" src="https://zl-tuangou.oss-cn-qingdao.aliyuncs.com/cMini/sel2.png" mode="widthFix"></image>
					</view>
				</view>
			</view>
			<view class="orderLine dFlex jBetween_aCenter" @tap='changePay("balance")'>
				<view class="lineTit dFlex jStart_aCenter">
					<view class="titIcon imgPublic">
						<image src="https://zl-tuangou.oss-cn-qingdao.aliyuncs.com/cMini/balance.png" mode="widthFix"></image>
					</view>
					<text>余额支付</text>
				</view>
				<view class="lineVal dFlex jEnd_aCenter">
					<view class="desc" v-if="reduce > 0">余额支付-￥{{reduce}}</view>
					<view class="statusIcon imgPublic">
						<image v-if="paytype != 'balance'" src="https://zl-tuangou.oss-cn-qingdao.aliyuncs.com/cMini/unsel.png" mode="widthFix"></image>
						<image v-if="paytype == 'balance'" src="https://zl-tuangou.oss-cn-qingdao.aliyuncs.com/cMini/sel2.png" mode="widthFix"></image>
					</view>
				</view>
			</view>
		</view> -->
		<!-- 券使用明细 -->
		<view class="cp_use" v-if='selcp.length'>
			<view class="cpOne" v-for="(item,index) in selcp" :key='index'>
				<view class="cpTitle dFlex jBetween_aCenter">
					<view class="cpLeft dFlex jStart_aCenter">
						<view class="tag" v-if="item.type == '0'">无门槛券</view>
						<view class="tag" v-if="item.type == '1'">满减券</view>
						<view class="tag" v-if="item.type == '2'">活动券</view>
						<view class="tag" v-if="item.type == '3'">立减券</view>
						<view class="tag" v-if="item.type == '4'">折扣券</view>
						<view class="cpName">{{item.title}}</view>
					</view>
					<view class="amount" v-if="item.type != '4'">￥<text>{{item.sub_price}}</text></view>
					<view class="amount" v-if="item.type == '4'"><text>{{item.discount}}</text>折</view>
				</view>
				<view class="shops">
					<view class="shopOne dFlex jStart_aStart" v-for="(item2,index2) in item.useShop" :key='index2'>
						<view class="shopImg imgPublic">
							<image :src="item2.main_img"></image>
						</view>
						<view class="shopname">{{item2.title}}</view>
					</view>
				</view>
			</view>
		</view>
		<view class="seat"></view>
		<!-- 是否满49 -->
		<view :class="['tj','dFlex','jBetween_aCenter',device == 'ios'?'ios_tj':'']">
			<view class="allCount">
				<view class="line1">
					<text class="txt0">{{'共'+allCount+'件 '}} </text>
					<text class="txt1">合计：</text> 
					<text class="txt2">¥</text>
					<text class="rmb">{{showPrice?(showPrice - cpCount).toFixed(2):'0.00'}}</text>
				</view>
				<view class="line2">共优惠<text>￥{{cpCount}}</text></view>
			</view>
			<view class="subBtn" @tap='subOrder'>提交订单</view>
		</view>
		<!-- 奖励弹窗 -->
		<view class="zz dFlex jCenter_aCenter" v-if="priceFlag">
			<view class="priceBox dFlex flexDirection jCenter_aCenter">
				<view class="priceDesc">
					<view class="priceImg imgPublic">
						<image src="https://zl-tuangou.oss-cn-qingdao.aliyuncs.com/cMini/priceToast.png" mode="widthFix"></image>
					</view>
					<view class="priceContent">
						<view class="desc">邀请{{need_num}}人成功下单获免单1次</view>
						<view class="getInBtn imgPublic" @tap.stop='getPrice'>
							<image src="https://zl-tuangou.oss-cn-qingdao.aliyuncs.com/cMini/getBtn.png" mode="widthFix"></image>
						</view>
					</view>
				</view>
				<view class="closeImg imgPublic" @tap.stop='closePrice'>
					<image src="https://zl-tuangou.oss-cn-qingdao.aliyuncs.com/cMini/closeIcon2.png" mode="widthFix"></image>
				</view>
			</view>
		</view>
		<!-- 优惠券选择弹窗 -->
		<view class="zz dFlex flexDirection jEnd_aCenter" v-if="couponFlag">
			<view class='coupon'>
				<view class="titles dFlex jCenter_aCenter">
					<!-- <view class="line"></view> -->
					<view class="tit">优惠券</view>
					<!-- <view class="line"></view> -->
				</view>
				<view class="tools dFlex jBetween_aCenter">
					<view class="count">优惠券({{coupon.length}})</view>
					<view class="explain">优惠券说明</view>
				</view>
				<view class="qList">
					<view class="cpOne" v-for="(item,index) in coupon" :key='index' @tap.stop='change_sekStatus(item)'>
						<view class="cpMain">
							<view class="cpBgImg imgPublic">
								<image v-if="!item.canUse" src="https://zl-tuangou.oss-cn-qingdao.aliyuncs.com/cMini/haveUse.png" mode="widthFix"></image>
								<image v-if="item.canUse" src="https://zl-tuangou.oss-cn-qingdao.aliyuncs.com/cMini/noUse.png" mode="widthFix"></image>
								<view class="statusIcon imgPublic" v-if="item.canUse">
									<image v-if="!item.selFlag" src="https://zl-tuangou.oss-cn-qingdao.aliyuncs.com/cMini/unsel.png" mode="widthFix"></image>
									<image v-if="item.selFlag" src="https://zl-tuangou.oss-cn-qingdao.aliyuncs.com/cMini/sel2.png" mode="widthFix"></image>
								</view>
							</view>
							<view class="cpContent dFlex jBetween_aCenter">
								<view class="contentLeft">
									<view class="tag" v-if="item.type == '0'">无门槛券</view>
									<view class="tag" v-if="item.type == '1'">满减券</view>
									<view class="tag" v-if="item.type == '2'">活动券</view>
									<view class="tag" v-if="item.type == '3'">立减券</view>
									<view class="tag" v-if="item.type == '4'">折扣券</view>
									<view class="content dFlex jStart_aStart">
										<!-- <view class="shopImg imgPublic">
											<image src="https://zl-tuangou.oss-cn-qingdao.aliyuncs.com/cMini/logo.png" mode="widthFix"></image>
										</view> -->
										<view class="cpDetail">
											<view class="toast" v-if="item.type == 3">仅限指定商品使用</view>
											<view class="cpName">{{item.title}}</view>
											<view class="time">{{item.start_time_text.substring(0,item.start_time_text.length-3)}}至{{item.end_time_text.substring(0,item.start_time_text.length-3)}}</view>
											<view class="expbtn dFlex jStart_aCenter" @tap.stop='changeRuleFlag(item)'>
												<text>详细信息</text>
												<view class="exBtn imgPublic">
													<image v-if="item.ruleFlag" src="https://zl-tuangou.oss-cn-qingdao.aliyuncs.com/cMini/open.png" mode="widthFix"></image>
													<image v-if="!item.ruleFlag" src="https://zl-tuangou.oss-cn-qingdao.aliyuncs.com/cMini/close.png" mode="widthFix"></image>
												</view>
											</view>
										</view>
									</view>
								</view>
								<view class="contentRight dFlex flexDirection jCenter_aCenter">
									<view class="cpCount" v-if="item.type != '4'">￥<text>{{item.sub_price}}</text></view>
									<view class="cpCount" v-if="item.type == '4'"><text>{{item.discount}}</text>折</view>
									<view class="condition" v-if="item.type != '3' && item.type != '0' && (item.type == '4' && item.discount_limit > 0)">满{{item.min_price}}元可用</view>
									<!-- <view class="useBtn">立即使用</view> -->
								</view>
							</view>
						</view> 
						<view class="explain" v-if="item.ruleFlag">
							<view class="line">{{item.rule}}</view>
						</view>
					</view>
				</view>
				<view class="btns dFlex jAround_aCenter" @tap.stop='couponFlag = false'>
					<view class="hui" @click='change_sekStatus("")'>不使用优惠券</view>
					<view class="btn">可减{{cpCount}}元，去结算</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				shopInfo:[],
				shopPrice:0.00,
				showPrice:0.00,
				addInfo:{},
				leaderInfo:{},
				status:'',// 1 商品详情购买  2 购物车购买
				allCount:0,
				device:getApp().globalData.platform,
				link:'',
				invite_id:'',
				need_num:'',
				priceFlag:false,
				couponFlag:false,
				
				source_id:'',
				coupon:[],
				cpCount:0.00,
				selcp:[],
				
				wallet:'',
				paytype:'wxpay',
				
				reduce:0,// 会员商品 一共减少的价格
				source:'',
				
				actType:'',
				actId:"",
			};
		},
		onLoad(e) {
			console.log(e);
			this.link = this.tool.objToUrl(e);
			this.status = e.status;
			if(this.status == '1'){
				this.actType = e.actType;
				this.actId = e.actId;
			}
			this.invite_id = e.inviteId;
			this.need_num = e.need_num;
			this.showPrice = 0;
			this.allCount = 0;
			this.source = e.source?e.source:'';
			this.shopInfo = JSON.parse(e.shopInfo);
			this.shopInfo.map((item,index)=>{
				this.source_id = index == this.shopInfo.length - 1?this.source_id + item.goods_id:this.source_id + item.goods_id+',';
				this.allCount = this.allCount + item.count;
				this.showPrice = this.showPrice + item.count * item.showPrice;
				this.shopPrice = this.shopPrice + item.count * item.showPrice;
				item.types = item.types?item.types.split(','):[];
				if(item.is_vip_goods){
					for(let i=0;i<item.count;i++){
						this.reduce = this.reduce + item.showPrice * (1 - item.vip_discount / 10);
					}
				}
			})
			this.reduce = (parseInt(this.reduce*100)/100).toFixed(2);
		},
		onShow(){
			// 地址列表
			this.initAdd();
			// 优惠券列表
			this.initCoupon();
			this.initwallet();
			this.$forceUpdate();
		},
		methods:{
			// 钱包余额
			initwallet(){
				this.tool.getData('/api/user/info',{},'',this).then(res=>{
					if(res){
						this.wallet = res.vip_rechage_balance;
					}
				}).catch(err=>{
					console.log(err);
				})
			},
			// 优惠券列表
			initCoupon(){
				this.tool.getData('/api/mall/getUseCoupon',{
					source:'0',
					source_id:this.source_id,
				}).then(res=>{
					if(res && res.length){
						res.sort(this.tool.sortBy('type',0));
						res.map((item,index)=>{
							item.selFlag = false;
							item.ruleFlag = false;
							item.canUse = true;
							if(item.type == '1'){//满减券
								if(item.appoint_type == '0'){//通用券
									if(item.min_price>this.showPrice){
										item.canUse = false;
									}
								}else{//品类券
									let kind = [];
									item.appointArr = item.appoint_id.split(',');
									this.shopInfo.map((item2,index2)=>{
										if(item2.types.length){
											for(let i=0;i<item2.types.length;i++){
												let idx = item.appointArr.indexOf(item2.types[i]);
												if(idx != '-1'){//属于该品类
													kind.push(item2);
													break;
												}
											}
										}
									})
									if(kind.length){
										let kindPrice = 0;
										kind.map((item2,index2)=>{
											kindPrice = kindPrice + item2.count * item2.showPrice;
										})
										if(kindPrice < item.min_price){
											item.canUse = false;
										}
									}
								}
							}
							if(item.type == '3'){//立减券 use_goods_id
								let idx = this.tool.getIdx(this.shopInfo,'goods_id',item.use_goods_id);
								if(idx == '-1'){
									item.canUse = false;
								}
							}
							if(item.type == '4'){//折扣券
								let kind = [];
								item.appointArr = item.appoint_id.split(',');
								this.shopInfo.map((item2,index2)=>{
									if(item2.types.length){
										for(let i=0;i<item2.types.length;i++){
											let idx = item.appointArr.indexOf(item2.types[i]);
											if(idx != '-1'){//属于该品类
												kind.push(item2);
												break;
											}
										}
									}
								})
								if(kind.length){
									let kindPrice = 0;
									kind.map((item2,index2)=>{
										kindPrice = kindPrice + item2.count * item2.showPrice;
									})
									if(kindPrice < item.discount_limit){
										item.canUse = false;
									}
								}
							}else if(item.type == "0"){//无门槛券
								let allPrice = 0;
								this.shopInfo.map((item2,index2)=>{
									let priceOne = item2.showPrice * item2.count;
									allPrice = allPrice+priceOne;
								});
								if(item.sub_price > allPrice){
									item.canUse = false;
								}
							}
						})
						res.sort(this.tool.sortBy('canUse',1));
						this.coupon = res;
					}
				}).catch(err=>{
					console.log(err);
				})
			},
			// 修改支付方式
			changePay(way){
				if(this.paytype != way){
					this.paytype = way;
					if(way == 'balance'){
						this.showPrice = parseFloat(this.showPrice) - parseFloat(this.reduce);
					}else{
						this.showPrice = parseFloat(this.showPrice) + parseFloat(this.reduce);
					}
				}
			},
			// 修改优惠券使用状态
			change_sekStatus(line){
				if(line.id){
					if(line.canUse){
						let lineType = line.type;
						let typeArr = [];
						this.coupon.map((item,index)=>{
							if(item.type == lineType){
								typeArr.push(item);
							}
						})
						typeArr.map((item,index)=>{
							if(item.id != line.id){
								item.selFlag = false;
							}
						})
						line.selFlag = !line.selFlag;
					}
				}else{
					this.coupon.map((item,index)=>{
						item.selFlag = false;
					})
				}
				this.calcPrice();
			},
			// 计算选中的优惠券的金额
			calcPrice(){
				this.cpCount = 0;
				this.selcp = [];//选中的优惠券
				this.coupon.map((item,index)=>{
					if(item.selFlag){
						item.useShop = [];
						this.selcp.push(item);
					}
				})
				if(this.selcp.length){
					this.selcp.map((item,index)=>{
						if(item.type == '0'){//无门槛券 
							this.cpCount = (parseFloat(this.cpCount) + parseFloat(item.sub_price)).toFixed(2);
							item.useShop = item.useShop.concat(this.shopInfo);
						}else if(item.type == '1'){// 满减券
							let kindPrice = 0;
							if(item.appoint_type == '0'){// 通用券
								this.cpCount = (parseFloat(this.cpCount) + parseFloat(item.sub_price)).toFixed(2);
								item.useShop = item.useShop.concat(this.shopInfo);
							}else if(item.appoint_type == '1'){//品类券
								item.appointArr = item.appoint_id.split(',');
								let kind = [];
								this.shopInfo.map((item2,index2)=>{
									if(item2.types.length){
										for(let i=0;i<item2.types.length;i++){
											let idx = item.appointArr.indexOf(item2.types[i]);
											if(idx != '-1'){//属于该品类
												kind.push(item2);
												item.useShop.push(item2);
												break;
											}
										}
									}
								})
								if(kind.length){
									kind.map((item2,index2)=>{
										kindPrice = kindPrice + item2.count * item2.showPrice;
									})
									if(kindPrice >= item.min_price){
										if(item.is_overly){//满减使用叠加
											let times = parseInt(kindPrice / item.min_price);// 叠加次数
											if(times == '1'){//只能用一次
												this.cpCount = (parseFloat(this.cpCount) + parseFloat(item.sub_price)).toFixed(2);
											}else{//叠加 times - 1次
												let overly_money = times * item.sub_price;
												if(this.selcp.length > 1){
													this.cpCount = (parseFloat(this.cpCount) + parseFloat(overly_money)).toFixed(2);
												}else{
													this.cpCount = (parseFloat(overly_money)).toFixed(2);
												}
											}
										}else{
											this.cpCount = (parseFloat(this.cpCount) + parseFloat(item.sub_price)).toFixed(2);
										}
									}
								}
							}
							
						}else if(item.type == '3'){//立减券
							this.shopInfo.map((item2,index2)=>{
								if(item2.goods_id == item.use_goods_id){
									item.useShop.push(item2);
									this.cpCount = (parseFloat(this.cpCount) + parseFloat(item.sub_price)).toFixed(2);
								}
							})
						}else if(item.type == '4'){//折扣券
							item.appointArr = item.appoint_id.split(',');
							let kind = [];
							this.shopInfo.map((item2,index2)=>{
								if(item2.types.length){
									for(let i=0;i<item2.types.length;i++){
										let idx = item.appointArr.indexOf(item2.types[i]);
										if(idx != '-1'){//属于该品类
											kind.push(item2);
											item.useShop.push(item2);
											break;
										}
									}
								}
							})
							if(kind.length){
								let kindPrice = 0;
								kind.map((item2,index2)=>{
									kindPrice = kindPrice + item2.count * item2.showPrice;
								})
								let afterPrice = kindPrice * (1 - item.discount / 10);
							    if(afterPrice > item.discount_limit){
									this.cpCount = (parseFloat(this.cpCount) + parseFloat(item.discount_limit)).toFixed(2);
							    }else{
									this.cpCount = (parseFloat(this.cpCount) + parseFloat(afterPrice)).toFixed(2);
							    }
							}
						}
					})
				}
			},
			// 修改使用规则开关
			changeRuleFlag(line){
				line.ruleFlag = !line.ruleFlag;
			},
			// 地址列表
			initAdd(){
				this.tool.getData('/api/user/getAddressList',{}).then(res=>{
					if(res){
						console.log(res);
						res.map((item,index)=>{
							if(item.is_default == 1){
								this.addInfo = item;
							}
						})
					}
				}).catch(err=>{
					console.log(err);
				})
			},
			// 关闭奖励
			closePrice(){
				this.priceFlag = false;
				uni.navigateBack({
					delta:1
				})
			},
			// 领取奖励
			getPrice(){
				uni.redirectTo({
					url:'../my/shareAdv?id='+this.shopInfo[0].id+'&inviteId='+this.invite_id,
					complete: () => {
						this.priceFlag = false;
					}
				})
			},
			// 提交订单
			subOrder(){
				if(!this.source){
					if(!this.addInfo.id){
						uni.showToast({
							title:'请选择提货人信息',
							icon:"none"
						})
						return
					}
					if(!this.leaderInfo.id){
						uni.showToast({
							title:'请选择提货点',
							icon:"none"
						})
						return
					}
				}
				let coupon = '';
				if(this.selcp.length){
					this.selcp.map((item,index)=>{
						coupon = index == this.selcp.length-1?coupon+item.id:coupon+item.id+',';
					})
				}
				let source = '';
				if(uni.getStorageSync('source')){
					let sourceTime = JSON.parse(uni.getStorageSync('source')).time;
					if(sourceTime + 60 * 60 * 1000 > new Date().getTime()){
						uni.removeStorageSync('source');
					}else{
						source = JSON.parse(uni.getStorageSync('source')).source;
					}
				}
				if(this.paytype == 'balance'){
					if(this.wallet < this.showPrice){
						uni.showToast({
							title:'余额不足',
							icon:'none'
						})
						/* uni.showModal({
							content:'余额不足 是否现在充值',
							success:(op)=>{
								if(op.confirm){
									uni.navigateTo({
										url:'/my/recharge',
										fail:(err)=>{
											console.log(err);
										}
									})
								}
							}
						}) */
						return;
					}
				}
				
				if(this.status == 1){
					var url = '/api/mall/createOrderByGoodsid',data = {
						goods_id:this.shopInfo[0].id,
						goods_attr_id:this.shopInfo[0].specId,
						num:this.shopInfo[0].count,
						address_id:this.leaderInfo.address_id?this.leaderInfo.address_id:0,
						receive_address_id:this.addInfo.id?this.addInfo.id:0,
						invite_id:this.invite_id?this.invite_id:'0',
						tjr_id:uni.getStorageSync('shareInfo')?uni.getStorageSync('shareInfo').shareId:'',
						coupon:coupon,
						source:this.source?this.source:0,
						paytype:this.paytype,
					};
					if(this.actType == '4'){
						url = '/api/mall/createOrderByNewUsers';
						data = {
							nu_id:this.actId,
							goods_list:JSON.stringify([{
								goods_id:this.shopInfo[0].id,
								num:this.shopInfo[0].count,
								goods_attr_id:this.shopInfo[0].specId,
								
							}]),
							address_id:this.leaderInfo.address_id?this.leaderInfo.address_id:0,
							receive_address_id:this.addInfo.id?this.addInfo.id:0,
							coupon:coupon,
						}
					}
					if(this.paytype == 'balance'){
						uni.showModal({
							content:'订单最终支付金额：'+(parseFloat(this.showPrice).toFixed(2))+'元',
							success: (op) => {
								if(op.confirm){//余额支付
									this.tool.getData(url,data).then(res=>{
										console.log(res);
										if(res){
											if(res.order_id){
												uni.showModal({
													content:'同款商品有未支付的订单,是否前去支付',
													success: (op) => {
														if(op.confirm){
															uni.redirectTo({
																url:'../my/orders'
															})
														}
													}
												})
											}else{
												this.tool.getData('/api/mall/orderPay',{
													oid:res.id
												}).then(payInfo=>{
													if(payInfo){
														uni.showToast({
															title:'订单支付成功',
															icon:"success"
														})
														setTimeout(()=>{
															uni.navigateBack({
																delta:1
															})
														},1650)
													}
												}).catch(err=>{
													console.log(err);
												})
											}
										}
									}).catch(err=>{
										console.log(err);
									})
								}
							}
						})
					}else{//微信支付
						this.tool.getData(url,data).then(res=>{
							console.log(res);
							if(res){
								if(res.order_id){
									uni.showModal({
										content:'同款商品有未支付的订单,是否前去支付',
										success: (op) => {
											if(op.confirm){
												uni.redirectTo({
													url:'../my/orders'
												})
											}
										}
									})
								}else{
									this.tool.getData('/api/mall/orderPay',{
										oid:res.id
									}).then(payInfo=>{
										console.log(payInfo);
										if(payInfo){
											uni.requestPayment({
												provider:'wxpay',
												timeStamp:payInfo.info.timeStamp,
												nonceStr:payInfo.info.nonceStr,
												package:payInfo.info.package,
												signType:payInfo.info.signType,
												paySign:payInfo.info.paySign,
												success: (pay) => {
													if(this.invite_id && this.need_num>0){
														this.priceFlag = true;
													}else{
														uni.showToast({
															title:'订单支付成功',
															icon:"success"
														})
														setTimeout(()=>{
															uni.navigateBack({
																delta:1
															})
														},1650)
													}
												},
												fail:(err)=>{
													console.log(err);
													uni.showToast({
														title:'取消支付',
														icon:"none"
													})
												}
											})
										}
									}).catch(err=>{
										console.log(err);
									})
								}
							}
						}).catch(err=>{
							console.log(err);
						})
					}
				}else{
					let ids = '';
					this.shopInfo.map((item,index)=>{
						index == this.shopInfo.length-1?ids = ids + item.id:ids = ids + item.id+',';
					})
					if(this.paytype == 'balance'){//余额支付
						uni.showModal({
							content:'订单最终支付金额：'+(parseFloat(this.showPrice).toFixed(2))+'元',
							success: (op) => {
								if(op.confirm){//余额支付
									this.tool.getData('/api/mall/createOrderByCartgoods',{
										ids:ids,
										address_id:this.leaderInfo.address_id?this.leaderInfo.address_id:0,
										receive_address_id:this.addInfo.id?this.addInfo.id:0,
										coupon:coupon,
										source:source,
										paytype:this.paytype,
										tjr_id:uni.getStorageSync('shareInfo')?uni.getStorageSync('shareInfo').shareId:'',
									}).then(res=>{
										if(res){
											// 支付id  res.id
											this.tool.getData('/api/mall/orderPay',{
												oid:res.id
											}).then(payInfo=>{
												console.log(payInfo);
												if(payInfo){
													uni.showToast({
														title:'订单支付成功',
														icon:"success"
													})
													setTimeout(()=>{
														uni.navigateBack({
															delta:1
														})
													},1650)
												}
											}).catch(err=>{
												console.log(err);
											})
										}
									}).catch(err=>{
										console.log(err);
									})
								}
							}
						})
					}else{//微信支付
						this.tool.getData('/api/mall/createOrderByCartgoods',{
							ids:ids,
							address_id:this.leaderInfo.address_id?this.leaderInfo.address_id:0,
							receive_address_id:this.addInfo.id?this.addInfo.id:0,
							coupon:coupon,
							source:source,
							paytype:this.paytype,
							tjr_id:uni.getStorageSync('shareInfo')?uni.getStorageSync('shareInfo').shareId:'',
						}).then(res=>{
							if(res){
								// 支付id  res.id
								this.tool.getData('/api/mall/orderPay',{
									oid:res.id
								}).then(payInfo=>{
									console.log(payInfo);
									if(payInfo){
										uni.requestPayment({
											provider:'wxpay',
											timeStamp:payInfo.info.timeStamp,
											nonceStr:payInfo.info.nonceStr,
											package:payInfo.info.package,
											signType:payInfo.info.signType,
											paySign:payInfo.info.paySign,
											success: (pay) => {
												uni.showToast({
													title:'订单支付成功',
													icon:"success"
												})
												setTimeout(()=>{
													uni.navigateBack({
														delta:1
													})
												},1650)
											},
											fail:(err)=>{
												console.log(err);
												uni.showToast({
													title:'取消支付',
													icon:"none"
												})
											}
										})
									}
								}).catch(err=>{
									console.log(err);
								})
							}
						}).catch(err=>{
							console.log(err);
						})
					}
				}
			},
			// 选择其他收货地址
			selAdd(){
				uni.navigateTo({
					url:'../my/address',
				})
			},
			// 选择自提点
			selZiti(){
				uni.navigateTo({
					url:'../my/ziti',
				})
			},
		}
	}
</script>

<style lang="scss">
	page{
		background: #F6F6F6;
	}
	.beforeOrder{
		width: 100%;
		padding: 12px;
		box-sizing: border-box;
		.zz{
			.coupon{
				width: 100%;
				border-top-left-radius: 40rpx;
				border-top-right-radius: 40rpx;
				background: white;
				max-height: 80%;
				position: relative;
				overflow: auto;
				padding-bottom: 80px;
				box-sizing: border-box;
				.btns{
					width: 100%;
					padding: 20rpx 0;
					border-top: 1px solid #D8D8D8;
					position: fixed;
					left: 0;
					bottom: 0;
					background: white;
					.hui{
						font-size: 12px;
						color: #666666;
					}
					.btn{
						width: 58.4%;
						text-align: center;
						color: white;
						border-radius: 50px;
						background: linear-gradient(180deg, #FC9700 0%, #FF5000 100%);
						padding: 24rpx 0;
						font-size: 16px;
					}
				}
				.qList{
					width: 100%;
					padding: 0 24rpx;
					box-sizing: border-box;
					.cpOne{
						width: 100%;
						background: white;
						border-radius: 20rpx;
						box-sizing: border-box;
						overflow: hidden;
						margin-bottom: 20rpx;
						.cpMain{
							width: 100%;
							position: relative;
							.cpBgImg{
								width: 100%;
								position: relative;
								.statusIcon{
									width: 40rpx;
									height: 40rpx;
									border-radius: 50%;
									background: white;
									position: absolute;
									top: 10rpx;
									right: 10rpx;
									image{
										width: 100%;
									}
								}
							}
							.cpContent{
								width: 100%;
								height: 100%;
								position: absolute;
								top: 0;
								left: 0;
								.contentLeft{
									width: 69%;
									height: 100%;
									padding:12rpx 24rpx;
									box-sizing: border-box;
									.content{
										width: 100%;
										.cpDetail{
											flex: 1;
											min-width: calc(100% - 70px);
											.toast{
												color: #666666;
												font-size: 12px;
												margin-bottom: 4rpx;
											}
											.cpName{
												margin-bottom: 4rpx;
												width: 100%;
												overflow: hidden;
												text-overflow: ellipsis;
												white-space: nowrap;
												font-size: 15px;
												font-weight: bold;
											}
											.time{
												color: #666666;
												font-size: 12px;
												margin-bottom: 12rpx;
											}
											.expbtn{
												color: #999999;
												font-size: 12px;
												.exBtn{
													width: 24rpx;
													height: 24rpx;
													margin-left: 8rpx;
												}
											}
										}
										.shopImg{
											width: 128rpx;
											height: 128rpx;
											margin-right:12rpx;
											image{
												width: 100%;
												height: 100%;
												border-radius: 20rpx;
											}
										}
									}
									.tag{
										font-size: 10px;
										padding: 2px 18rpx;
										color: #FD5605;
										background: #FFF0E8;
										margin-bottom: 8rpx;
										width: max-content;
									}
								}
								.contentRight{
									width: 31%;
									height: 100%;
									padding: 24rpx;
									box-sizing: border-box;
									color: white;
									.useBtn{
										width: max-content;
										padding: 10rpx 16rpx;
										border-radius: 50px;
										background: white; 
										color: #FF5000;
										font-size: 12px;
									}
									.condition{
										font-size: 12px;
										margin-bottom: 10rpx;
									}
									.cpCount{
										font-size: 16px;
										font-weight: bolder;
										text{
											font-size: 34px;
										}
									}
								}
							}
						}
						.explain{
							width: 100%;
							padding: 24rpx;
							box-sizing: border-box;
							color: #999999;
							font-size: 12px;
							background: white;
							line-height: 38rpx;
						}
					}
				}
				.tools{
					color: #999999;
					font-size: 12px;
					margin-bottom: 30rpx;
					padding: 0 24rpx;
					width: 100%;
					box-sizing: border-box;
				}
				.titles{
					width: 100%;
					padding: 40rpx 0;
					font-size: 20px;
					font-weight: bold;
					.line{
						width: 160rpx;
						height: 0;
						border: 1px solid #C1C1C1;
						margin: 0 20rpx;
					}
				}
			}
			.priceBox{
				width: 86.66%;
				.priceDesc{
					position: relative;
					width:100%;
					.priceContent{
						position:absolute;
						top: 0;
						left: 0;
						width: 100%;
						height:100%; 
						padding: 216rpx 105rpx 84rpx;
						box-sizing: border-box;
						.getInBtn{
							width: 100%;
							margin-top: 130rpx;
						}
						.desc{
							width: 80%;
							margin: 0 auto;
							text-align: center;
							color: #E20417;
							font-size: 42rpx;
							font-weight: bolder;
							line-height: 60rpx;
						}
					}
					.priceImg{
						width:100%;
					}
				}
				.closeImg{
					width: 72rpx;
					height: 72rpx;
					border-radius: 50%;
					margin: 0 auto;
				}
			}
		}
		.toastFull{
			width: 100%;
			background: #FFFAE1;
			padding: 12rpx 30rpx;
			box-sizing: border-box;
			color: #FC9700;
			font-size: 12px;
			position: fixed;
			left:0;
			.pin{
				width: max-content;
				padding: 6rpx 14rpx;
				color: white;
				border-radius: 6rpx;
				background: #FC9700;
			}
		}
		.tj{
			width: 100%;
			padding: 6px 12px;
			background: white;
			box-sizing: border-box;
			position: fixed;
			bottom: 0;
			left: 0;
			.subBtn{
				width: max-content;
				padding: 8px 32px;
				border-radius: 40px;
				color: white;
				background:$col_active;
				font-weight: bold;
			}
			.allCount{
				flex: 1;
				text-align: right;
				margin-right: 10px;
				.line2{
					font-size: 12px;
					text{
						color: #FC4424;
					}
				}
				.line1{
					width: 100%;
					// margin-bottom: 4rpx;
					.txt0{
						color: #999999;
					}
					.txt1{
						display: inline-block;
						margin-right: 4px;
					}
					.txt2,.rmb{
						color: #FC4424;
					}
					.rmb{
						font-size: 20px;
						font-weight: bold;
					}
				}
			}
		}
		.ios_tj{
			padding-bottom: env(safe-area-inset-bottom);
		}
		.cp_use{
			width: 100%;
			border-radius: 8px;
			padding: 16px 12px;
			background: white;
			box-sizing: border-box;
			margin-top: 12px;
			.cpOne{
				width: 100%;
				padding-bottom: 6px;
				.shops{
					width: 100%;
					.shopOne{
						width: 100%;
						padding: 6px;
						box-sizing: border-box;
						margin-bottom: 6px;
						.shopname{
							width: calc(100% - 46px);
							display: -webkit-box;
						    overflow: hidden;  
						    -webkit-line-clamp: 2;
						    -webkit-box-orient: vertical;
						}
						.shopImg{
							width:80rpx;
							height: 80rpx;
							margin-right: 6px;
							image{
								width: 100%;
								height: 100%;
								border-radius: 4px;
							}
						}
					}
					.shopOne:last-child{
						margin: 0;
					}
				}
				.cpTitle{
					width: 100%;
					padding: 8px 0;
					border-bottom: 1px solid #bfbfbf;
					.cpLeft{
						width: 80%;
						.cpName{
							width: 65%;
							font-weight: 14px;
							font-weight: bold;
							margin-left: 8px;
							overflow: hidden;
							text-overflow: ellipsis;
							white-space: nowrap;
						}
						.tag{
							padding: 2px 18rpx;
							color: #FD5605;
							background: #FFF0E8;
							width: max-content;
							font-size: 12px;
						}
					}
					.amount{
						margin-left: 8px;
						color: #FF5000;
						font-weight: bold;
						font-size: 12px;
					}
				}
			}
		}
		.shopMsg{
			width: 100%;
			border-radius: 8px;
			padding: 16px 12px;
			background: white;
			box-sizing: border-box;
			margin-bottom: 20rpx;
			.orderLine{
				width: 100%;
				margin-bottom: 12px;
				color: #666666;
				.lineVal{
					.desc{
						width: max-content;
						background: #FFF0E8;
						padding: 4rpx 12rpx;
						border-radius:4rpx;
						color: #FF5000;
					}
					.statusIcon{
						width: 44rpx;
						height:44rpx;
						margin-left: 12rpx;
						padding: 1px;
						box-sizing: border-box;
					}
					.toast{
						color: #999999;
					}
					.condition{
						width: max-content;
						padding: 4rpx 14rpx;
						color: #FF5000;
						background: rgba(255,240,232,0.39);
						border-radius: 4px;
					}
					.rightIcon{
						width: 20rpx;
						height: 20rpx;
						margin-left: 4rpx;
					}
				}
				.lineTit{
					width: max-content;
					text{
						color: #333333;
					}
					.titIcon{
						width: 40rpx;
						height: 40rpx;
						margin-right: 16rpx;
					}
				}
			}
			.orderLine:last-child{
				margin: 0;
			}
			.shopList{
				width: 100%;
				margin-bottom: 24px;
				.shopInfo{
					width: 100%;
					margin-bottom: 8px;
					.shopImg{
						width:80px;
						height: 80px;
						overflow: hidden;
						background: white;
						margin-right: 12px;
						border-radius: 8px;
					}
					.other{
						flex: 1;
						.price{
							font-size: 14px;
							color: #333333;
							margin-left: 5px;
						}
						.selSpec{
							font-size: 14px;
							color: #999999;
							margin: 10px 0;
						}
						.shopName{
							font-size: 15px;
						}
					}
				}
				.shopInfo:last-child{
					margin: 0;
				}
			}
		}
		.teamInfo{
			width:100%;
			margin: 0 auto;
			background: white;
			padding: 24rpx;
			margin-bottom: 12px;
			border-radius: 20rpx;
			.base{
				width: 100%;
				margin-bottom: 6px;
				color: #666666;
				.info_content{
					flex: 1;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
				}
				.timeDetail{
					flex: none;
					width: max-content!important;
					color: white;
					background: linear-gradient(180deg, #FCB900 0%, #FF6319 100%);
					font-size: 12px;
					padding: 4rpx 10rpx;
					border-radius: 8rpx;
				}
				.baseLeft{
					width: 82%;
				}
				/* .exchange{
					width: auto;
					margin-left: 6px;
					font-size: 12px;
					.rightIcon{
						width: 20px;
						margin-left: 2px;
					}
				} */
				.titles{
					font-weight: bold;
					margin-right: 6px;
					.addIcon{
						width: 16px;
						height: 16px;
						margin-right: 6px;
					}
				}
			}
			.base:last-child{
				margin: 0;
			}
			.userInfo{
				padding:0 0 8px;
				border-bottom: 1px solid #F5F6F7;
				margin-bottom: 12px;
				.tuanzhang{
					flex: 1;
					.tag{
						width: max-content;
						font-size: 12px;
						color: #FB5D02;
						line-height: 20px;
						padding: 0 8px;
						border-radius: 40px;
						background: linear-gradient(90deg, #FEE2A2 0%, #FDEACA 100%);
						font-weight: bold;
						margin-left: 8px;
					}
					.userTx{
						width: 40px;
						height: 40px;
						border-radius: 50%;
						margin-right: 12px;
						image{
							width: 40px;
							height: 40px;
						}
					}
				}
				.distance{
					width: auto;
					color: #666666;
					.distanceIcon{
						width: 16px;
						margin-right: 4px;
					}
				}
			}
		}
		.add{
			width: 100%;
			padding: 12px;
			box-sizing: border-box;
			background: white;
			border-radius: 8px;
			margin-bottom: 12px;
			.addIcon{
				width: 24px;
				height: 24px;
				margin-right: 4px;
			}
			.selAdd{
				flex: 1;
				.showAdd{
					font-size: 14px;
					margin-top: 8px;
				}
				.userInfo{
					font-weight: bold;
					font-size: 16px;
					.username{
						margin-right: 10px;
					}
				}
			}
			.unselAdd{
				flex: 1;
				font-size: 16px;
				color: #666666;
			}
			.rightIcon{
				width: 20px;
				height: 20px;
			}
		}
	}
</style>
